package com.xjcs.saplingplan.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.xjcs.saplingplan.R
import com.xjcs.saplingplan.base.BaseVbActivity
import com.xjcs.saplingplan.const.AppMainTab
import com.xjcs.saplingplan.databinding.ActivityMainFragmentBinding
import com.xjcs.saplingplan.ui.fragment.CountdownFragment
import com.xjcs.saplingplan.ui.fragment.FocusFragment
import com.xjcs.saplingplan.ui.fragment.MemoFragment
import com.xjcs.saplingplan.ui.fragment.PlanFragment
import com.xjcs.saplingplan.ui.fragment.StatisticsFragment
import com.xjcs.saplingplan.ui.fragment.ViewFragment

class MainFragmentActivity : BaseVbActivity<ActivityMainFragmentBinding>() {

    companion object{

        const val MODULE = "module"

        fun startActivity(context: Context, module: AppMainTab){
            val intent = Intent(context, MainFragmentActivity::class.java)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            intent.putExtra(MODULE, module.desc)
            context.startActivity(intent)
        }
    }

    override fun getViewBinding(): ActivityMainFragmentBinding {
        return ActivityMainFragmentBinding.inflate(layoutInflater)
    }

    override fun initUi(savedInstanceState: Bundle?) {
        val module = intent.getStringExtra(MODULE)
        val fragment: Fragment? = when(module){
            AppMainTab.INVENTORY.desc -> {
                PlanFragment()
            }
            AppMainTab.VIEW.desc -> {
                ViewFragment()
            }
            AppMainTab.FOCUS.desc -> {
                FocusFragment()
            }
            AppMainTab.STATISTICS.desc -> {
                StatisticsFragment()
            }
            AppMainTab.COUNTDOWN.desc -> {
                CountdownFragment()
            }
            AppMainTab.MEMO.desc -> {
                MemoFragment()
            }
            else -> {
                null
            }
        }
        fragment?.let {
            supportFragmentManager.beginTransaction()
                .replace(R.id.frameLayout, it)
                .commit()
        }
    }

    override fun registerObserver() {
    }

    override fun initListener() {
    }
}